Week 8
Old Dominion University
Types of Trends:
lm(y ~ t, df)arima(df$y, xreg = t)arima(df$y, c(1, 0, 0))arima(df$y, c(0, 1, 0))\[Y_t = \alpha + \beta Y_{t-1} + e_t\]
\[E[Y_t] = \frac{\alpha}{1-\beta}\]
\[\text{Var}(Y_t) = \frac{\sigma^2}{1-\beta^2}\]
\[Y_t = 10 + .3Y_{t-1} + e_t\]
\[Y_t = 10 + .3Y_{t-1} + e_t\]
\[Y_t = 10 + .3Y_{t-1} + e_t\]
\[Y_t = 10 + .3Y_{t-1} + e_t\]
\[\small Y_t = \alpha t + e_t\]
\[\small \begin{align} \\ E[Y_t] = \alpha t \end{align}\]
\[\small \begin{align} \\ \\ \text{Var}(Y_t) = \sigma^2 \end{align}\]
\[\small \begin{align} Y_t &= \alpha + Y_{t-1} + e_t \\&= \alpha + (\alpha + Y_{t-2} + e_{t-1}) +e_t \end{align}\]
\[\small E[Y_t] = E[ \ \sum_{i=0}^{t}\alpha + \sum_{i=0}^{t}e_i \ ] = \alpha t\]
\[\small \begin{align} \text{Var}(Y_t) &= \text{Var}( \ \sum_{i=0}^{t}\alpha + \sum_{i=0}^{t}e_i \ ) \\ &= 0 + \sum_{i=0}^{t}\text{Var}(e_i) \end{align}\]
Types of Seasonality:
arima(df$y, xreg = mat[,2:12])arima(df$y, seasonal = list(order = c(1, 0, 0), period = 12))arima(df$y, seasonal = list(order = c(0, 1, 0), period = 12))How to get auto.arima to use seasonal components:
df$y, that is a monthly time series starting in 2005-06-01.y_ts <- ts(df$y, start = c(2005, 06, 1), frequency = 12)auto.arima(y_ts)N <- 12*12
t <- 1:(N)
shocks <- rnorm(N)
v1 <- rep(0, N)
v2 <- rep(0, N)
v3 <- rep(0, N)
v1 <- t + shocks
v2[1] <- shocks[1] + 1
for(i in 2:length(t)) v2[i] <- .4*v2[i-1] + shocks[i] + 1
v3[1] <- shocks[1] + 1
for(i in 2:length(t)) v3[i] <- v3[i-1] + shocks[i] + 1
plot(t, v1, col = "tomato", type = "l",
ylim = range(v1, v2, v3), xlab = "", ylab = "")
lines(t, v2, col = "dodgerblue")
lines(t, v3, col = "mediumseagreen")
legend("topleft", bty = "n", pch = 15, cex = 1.33,
col = c("tomato", "dodgerblue", "mediumseagreen"),
legend = c(expression(paste("Y"[t], " = t + e"[t])),
expression(paste("Y"[t], " = 1 + .4*Y"[t-1]," + e"[t])),
expression(paste("Y"[t], " = 1 + Y"[t-1]," + e"[t]))))
legend("left", bty = "n", pch = c(NA, rep(15, 3)), cex = 1.33,
col = c("black", "tomato", "dodgerblue", "mediumseagreen"),
legend = c(expression(paste("E[Y"[t=144],"]:")),
144, 1.67, 144))\[Y_t = t + e_t\]
\[Y_t = 1 + .4Y_{t-1} + e_t\]
\[Y_t = 1 + Y_{t-1} + e_t\]
t <- rep(1:12, 12)
shocks <- rnorm(N)
v1 <- rep(0, N)
v2 <- rep(0, N)
v3 <- rep(0, N)
v1 <- abs(t-6) + shocks - 3
v12 <- abs(t-6) + shocks - 3 + (1:length(t)) / 12
v2[1:12] <- shocks[1:12]
for(i in 13:length(t)) v2[i] <- .4*v2[i-12] + shocks[i] + 1
v3[1:12] <- shocks[1:12]
for(i in 13:length(t)) v3[i] <- v3[i-12] + shocks[i] + 1
plot(1:length(t), v1, lwd = 3,
col = alpha("tomato", .4), type = "l",
ylim = range(v1, v2, v3, v12),
xlab = "", ylab = "")
lines(1:length(t), v2, lwd = 3,
col = alpha("dodgerblue", .4))
lines(1:length(t), v3, lwd = 3,
col = alpha("mediumseagreen", .4))
lines(1:length(t), v12, lwd = 3,
col = alpha("orchid", .4))
legend("topleft", bty = "n", pch = 15, cex = 1.33,
col = c("tomato", "orchid", "dodgerblue", "mediumseagreen"),
legend = c(expression(paste("Y"[t], " = ", alpha[S], " + e"[t])),
expression(paste("Y"[t], " = t/12 + ", alpha[S], " + e"[t])),
expression(paste("Y"[t], " = .4*Y"[t-12]," + e"[t])),
expression(paste("Y"[t], " = Y"[t-12]," + e"[t]))))\[Y_t = \alpha_S + e_t\]
\[Y_t = t/12 + \alpha_S + e_t\]
\[Y_t = 1 + .4 * Y_{t-12} + e_t\]
\[Y_t = 1 + Y_{t-12} + e_t\]
\[\Delta Y_t = Y_t - Y_{t-1} = 1 + (Y_{t-12} - Y_{t-13}) + e_t\]
\[\Delta_{12} Y_t = Y_t - Y_{t-12} = 1 + (Y_{t-12} - Y_{t-24}) + e_t\]
Is this stationary?
Look at the variance:
If increasing, stochastic (diff across period)
If constant:
\[Y_{t} = 1 + .4Y_{t-1} + .4Y_{t-12} + e_t\]
\[Y_{t} = 1 - .4Y_{t-1} + .4Y_{t-12} + e_t\]
\[Y_{t} = 1 + .4Y_{t-1} + .4Y_{t-12} + e_t\]
Call:
arima(x = v4, order = c(1, 0, 0), seasonal = list(order = c(1, 0, 0), period = 12))
Coefficients:
ar1 sar1 intercept
0.5013 0.5055 4.8013
s.e. 0.0455 0.0470 0.2038
sigma^2 estimated as 1.148: log likelihood = -644.68, aic = 1297.37
\[Y_{t} = 1 - .4Y_{t-1} + .4Y_{t-12} + e_t\]
Call:
arima(x = v5, order = c(1, 0, 0), seasonal = list(order = c(1, 0, 0), period = 12))
Coefficients:
ar1 sar1 intercept
-0.4558 0.4736 1.0223
s.e. 0.0450 0.0448 0.0625
sigma^2 estimated as 1.039: log likelihood = -622.95, aic = 1253.91
p <- predict(reg, n.ahead = 24)
plot(1:(length(air)),
rep(0, length(air)),
type = "n", xlab = "Time",
ylab = "Air Passengers",
ylim = exp(range(p$pred + 1.645*p$se, air1)))
lines(1:length(air), exp(air), col = "tomato", lwd = 2)
lines(1:length(air1), exp(air1), lwd = 2)
polygon(x = c(1:24 + length(air1),
rev(1:24 + length(air1))),
y = c(exp(p$pred + 1.645*p$se),
rev(exp(p$pred - 1.645*p$se))),
col = alpha("dodgerblue", .3), border = NA)
lines(1:24 + length(air1), exp(p$pred),
col = "dodgerblue", lwd = 2, lty = 2)
abline(v = 120, lty = 2, col = alpha("black", .6))For both BIC and AIC, smaller is better.
Both BIC and AIC penalize the model when lags increase.
AIC penalizes less than BIC for more parameters, and therefore chooses models with more lags.
BIC picks which model is most likely to be true given the data whereas AIC picks\(^*\) the model with lowest forecast risk.
ECON 707/807: Econometrics II